<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-sys__dict">
      <!-- <div class="status">
        <span
          v-for="(item, index) in roomStatus"
          :key="index"
          :style="{ background: roomStatusColor[index] }"
        >
          {{ item }}
        </span>
      </div> -->
      <el-form
        :inline="true"
        :model="dataForm"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item v-if="showMs">
          <el-select
            v-model="dataForm.homestayId"
            placeholder="关联民宿"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="item in homestays"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item v-if="showMs">
          <el-select
            v-model="dataForm.islandId"
            placeholder="所属区域"
            clearable
            style="width: 100%"
          >
            <el-option
              v-for="item in scenicOptions"
              :key="item.id"
              :label="item.scenicName"
              :value="item.scenicName"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="dataForm.amountSort"
            placeholder="订单排序"
            clearable
          >
            <el-option
              :value="item.val"
              v-for="item in amountSortList"
              :key="item.val"
              :label="item.label"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model="dataForm.houseBaseId"
            placeholder="房型"
            clearable
          >
            <el-option
              :value="item.houseBaseId"
              v-for="item in roomType"
              :key="item.houseBaseId"
              :label="item.name"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item>
                <el-select v-model="dataForm.orderStatus" placeholder="客房状态" clearable>
                    <el-option :value="item.val" v-for="item in roomStatus" :key="item.val" :label="item.label">
                    </el-option>
                </el-select>
            </el-form-item> -->
        <el-form-item>
          <el-select
            v-model="dataForm.orderStatus"
            placeholder="订单状态"
            clearable
          >
            <el-option
              :value="item.val"
              v-for="item in roomStatus"
              :key="item.val"
              :label="item.label"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="" prop="guestSourceId">
          <el-select
            v-model="dataForm.guestSourceId"
            placeholder="客户来源"
            clearable
          >
            <el-option
              v-for="item in laiyuan"
              :key="item.id"
              :label="item.guestSource"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            v-model="dataForm.arriveDate"
            value-format="yyyy-MM-dd"
            type="date"
            placeholder="入住开始日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-date-picker
            v-model="dataForm.leaveDate"
            value-format="yyyy-MM-dd"
            type="date"
            placeholder="入住结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.orderCode"
            placeholder="订单编号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.guestPhone"
            placeholder="联系电话"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="dataForm.guestName"
            placeholder="联系人姓名"
            clearable
          ></el-input>
        </el-form-item>
        <!-- <el-form-item>
          <el-input
            v-model="dataForm.name"
            placeholder="请输入企业名称"
            clearable
          ></el-input>
        </el-form-item> -->
        <el-form-item>
          <el-button @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('hotel:hotelorder:delete')"
            type="danger"
            @click="deleteHandle()"
            >{{ $t("deleteBatch") }}</el-button
          >
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        :header-row-style="{ display: 'none' }"
        @selection-change="dataListSelectionChangeHandle"
        @sort-change="dataListSortChangeHandle"
        style="width: 100%"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          prop="breakfastName"
          label="早餐名称"
          header-align="center"
          min-width="120"
        >
          <template slot-scope="scope">
            <div class="cover"></div>
            <div style="position: relative">
              <p class="innerP">
                客房状态<span
                  :style="{
                    background: roomStatusColor[scope.row.orderStatus],
                  }"
                  >{{ scope.row.orderStatus | delStatus }}</span
                >
              </p>
              <p class="innerP">所属区域:{{ scope.row.islandName }}</p>
              <p class="innerP">订单来源:{{ scope.row.guestSourceName }}</p>
              <p class="innerP">创建时间:{{ scope.row.orderTime }}</p>
              <p class="innerP">民宿订单号:{{ scope.row.orderCode }}</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="price"
          label="价格"
          min-width="200px"
          header-align="center"
        >
          <template slot-scope="scope">
            <p class="innerP">民宿名称:{{ scope.row.homestayName }}</p>

            <p class="innerP">
              入住时间:{{ scope.row.arriveDate }}---{{
                scope.row.leaveDate
              }}共{{ scope.row.num }}晚
            </p>
            <p class="innerP">
              <i class="el-icon-user"></i>{{ scope.row.guestName
              }}<i class="el-icon-phone"></i><i @click="showReal=scope.$index">{{ scope.$index===showReal ? scope.row.realPhone : scope.row.guestPhone }}</i>
            </p>
            <p class="red innerP">￥{{ scope.row.orderAmount }}</p>
          </template>
        </el-table-column>
        <el-table-column
          :label="$t('handle')"
          fixed="right"
          header-align="center"
          align="center"
          width="200"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              size="small"
              v-if="$hasPermission('hotel:hotelorder:info')"
              @click="lookDetail(scope.row.id)"
              >详情</el-button
            >
            <el-button
              type="text"
              size="small"
              v-if="$hasPermission('hotel:hotelorder:delete')"
              @click="deleteHandle(scope.row.id)"
              >{{ $t("delete") }}</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 详情 -->
      <look-detail
        v-if="lookDetailVisible"
        ref="lookDetail"
        @refreshDataList="getDataList"
      ></look-detail>
    </div>
  </el-card>
</template>

<script>
var that;
import mixinViewModule from "@/mixins/view-module";
import lookDetail from "./lookDetail";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/hotel/order/page",
        getDataListIsPage: true,
        deleteURL: "/hotel/order",
        deleteIsBatch: true,
        createdIsNeed: false,
      },
      scenicOptions: [],
      homestays: [],
      showMs: false,
      roomStatus: [
        {
          val: 4,
          label: "已取消",
        },
        {
          val: -2,
          label: "待支付",
        },
        {
          val: -1,
          label: "待确定",
        },
        {
          val: 1,
          label: "已预订",
        },
        {
          val: 2,
          label: "已入住",
        },
        {
          val: 3,
          label: "已退房",
        },
        {
          val: 5,
          label: "已退款",
        },
      ],
      payState: [
        {
          val: 3,
          label: "已完成",
        },
        {
          val: -3,
          label: "已退款",
        },
        {
          val: -2,
          label: "待支付",
        },
        {
          val: -1,
          label: "已取消",
        },
        {
          val: 1,
          label: "已支付",
        },
        {
          val: 0,
          label: "待支付",
        },
        {
          val: 5,
          label: "已退款",
        },
      ],
      roomStatusColor: {
        "-2": "#ccc",
        "-1": "#6faef1",
        1: "#f29130",
        2: "#67c23a",
        3: "#969799",
        4: "#AAA",
        5: "#AAA",
      },
      amountSortList: [
        {
          label: "升序",
          val: 0,
        },
        {
          label: "降序",
          val: 1,
        },
      ],
      roomType: [],
      laiyuan: [],
      dataForm: {
        amountSort: "",
        houseBaseId: "",
        status: "",
        orderStatus: "",
        guestName: "",
        guestPhone: "",
        checkInType: "",
        guestSourceId: "",
        orderCode: "",
        arriveDate: "",
        leaveDate: "",
        todayOrder: null,
        homestayId: this.$store.state.user.homestayId || "",
        islandId: "",
      },
      dialogFormVisible: false,
      showReal:''
    };
  },
  watch: {
    "dataForm.homestayId": {
      handler(newval, oldval) {
        if (newval && newval != oldval) {
          this.getRoomType();
        } else {
          this.roomType = [];
        }
      },
      immediate: true,
    },
  },
  components: {
    lookDetail,
  },
  activated() {
    let state = this.$route.query.state;
    if (state == "all") {
      let arriveDate = new Date().format("yyyy-MM-dd");
      this.dataForm.arriveDate = arriveDate;
      this.getDataList();
    } else {
      this.dataForm.arriveDate = "";
    }
  },
  created() {
    that = this;
    this.dataForm.orderStatus = this.orderStatus;
    this.dataForm.status = this.status;
    this.getRoomType();
    this.getLaiyuan();
    this.getDataList();
    this.getScenicOptions();
    this.getHomestay();
    if (
      this.$store.state.user.roleList &&
      this.$store.state.user.roleList.indexOf("1712742759269081090") > -1
    ) {
      this.showMs = true;
    }
  },
  props: ["orderStatus", "status"],
  filters: {
    delStatus(val) {
      if (val) {
        let d = that.roomStatus.filter((item) => item.val == val);
        if (d.length != 0) {
          return d[0].label;
        }
      }
    },
  },
  methods: {
    //岛屿
    getScenicOptions() {
      this.$http
        .get("scenic/isscenic/selectScenicList", {})
        .then(({ data: res }) => {
          if (res.msg == "success") {
            this.scenicOptions = res.data;
          }
        });
    },
    getHomestay() {
      this.$http
        .get("/hotel/homestay/getHomestayDownBox")
        .then(({ data: res }) => {
          if (res.code == 0) {
            this.homestays = res.data;
          }
        });
    },
    //获取房型
    getRoomType() {
      this.$http
        .get("/hotel/house/base/getHouseSearchBox/" + this.dataForm.homestayId)
        .then(({ data: res }) => {
          if (res.code == 0) {
            this.roomType = res.data;
          }
        });
    },
    //获取来源
    getLaiyuan() {
      this.$http
        .get("/hotel/guest/page", {
          params: {
            homestayId: this.$store.state.user.homestayId,
            limit: 100,
            page: 1,
          },
        })
        .then((res) => {
          this.laiyuan = res.data.data.list;
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.innerP {
  margin: 8px 0;

  &.red {
    color: #f44;
    font-size: 24px;
    font-weight: 600;
  }

  span {
    display: inline-block;
    padding: 4px;
    border-radius: 4px;
    color: #fff;
    margin-left: 5px;
  }
}

.cover {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
  background-color: #f5f5f5;
}

.el-icon-user,
.el-icon-phone {
  font-size: 20px;
}

.el-icon-phone {
  margin-left: 20px;
}

.status {
  display: flex;
  gap: 20px;
  color: #fff;
  margin-bottom: 20px;

  span {
    padding: 5px;
    border-radius: 5px;
  }
}
</style>
